package com.itheima.service.Impl;

import com.itheima.mapper.deptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service  //将创建对象的权力给spring,spring将创建好的对象放入spring容器中 或者叫IOC容器中   这就叫控制反转
public class DeptServiceImpl implements DeptService {

    @Autowired//容器为应用程序提供运行时所依赖的资源,就是给成员变量赋值
    private deptMapper deptmapper;

    @Override
    public List<Dept> querylist() {
        return deptmapper.list();
    }

    @Override
    public void delete(Integer id) {
        deptmapper.delete(id);
    }

    @Override
    public void save(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptmapper.insert(dept);
    }

    @Override
    public Dept getDept(Integer id) {
        return deptmapper.getDeptById(id);

    }

    @Override
    public void update(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptmapper.update(dept);
    }


}
